﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Lottery.Control {
    public partial class EachMediaData : UserControl {
        public EachMediaData() {
            InitializeComponent();

            editPreNumber.Items.Clear();
            editPreNumber.Items.Add("");
            editPreNumber.Items.Add("3");
            editPreNumber.Items.Add("1");
            editPreNumber.Items.Add("0");
            editPreNumber.Items.Add("310");
            editPreNumber.SelectedIndex = 0;
        }

        private int order = 0;

        /// <summary>
        /// 奖号
        /// </summary>
        public string PreNumber {
            get { return editPreNumber.Text; }
            set { editPreNumber.SelectedIndex = (value == null) ? 0 : editPreNumber.Items.IndexOf(value); }
        }

        /// <summary>
        /// 场次
        /// </summary>
        public int Order {
            get { return order; }
            set {
                order = value;
                labelOrder.Text = string.Format("第 {0} 场", order);
            }
        }

        private System.Windows.Forms.Control jumpToNext;
        /// <summary>
        /// 按回车键的时候，焦点跳转到的控件
        /// </summary>
        public System.Windows.Forms.Control JumpToNext {
            get { return jumpToNext; }
            set {
                jumpToNext = value;
                
                edit0.JumpToNext = value;
            }
        }

        public int Three {
            get { return edit3.Value; }
            set { edit3.Text = value.ToString(); }
        }

        public int One {
            get { return edit1.Value; }
            set { edit1.Text = value.ToString(); }
        }

        public int Zero {
            get { return edit0.Value; }
            set { edit0.Text = value.ToString(); }
        }

        public void Set310(int? three, int? one, int? zero) {
            edit3.Text = three.HasValue ? three.ToString() : string.Empty;
            edit1.Text = one.HasValue ? one.ToString() : string.Empty;
            edit0.Text = zero.HasValue ? zero.ToString() : string.Empty;
        }

        public void Clear() {
            edit0.Text = string.Empty;
            edit1.Text = string.Empty;
            edit3.Text = string.Empty;
            editPreNumber.SelectedIndex = 0;
        }

        /// <summary>
        /// 是否已经录入了数据
        /// </summary>
        public bool IsOK {
            get { return edit3.Text != string.Empty && edit1.Text != string.Empty && edit0.Text != string.Empty; }
        }

        /// <summary>
        /// 把焦点设置在没有输入数据的Edit上
        /// </summary>
        public void FocusOnEmptyEdit() {
            if (IsOK) {
                return;
            }

            if (edit3.Text == string.Empty) {
                edit3.Focus();
                return;
            }
            if (edit1.Text == string.Empty) {
                edit1.Focus();
                return;
            }
            if (edit0.Text == string.Empty) {
                edit0.Focus();
                return;
            }
        }

        private void EachMediaData_EnabledChanged(object sender, EventArgs e) {
            label2.Visible = label3.Visible = label4.Visible = this.Enabled;
            edit0.Visible = edit1.Visible = edit3.Visible = this.Enabled;
        }
    }
}